/*!
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *
 *    Author: flareguner
 *    E-Mail: flareguner@gmail.com
 *    Years: 2010-2011
 */




#include <QDebug>
#include <QtCore/QString>
#include <QtNetwork/QNetworkProxy>
#include <QtCore/QStringList>
#include <QApplication>
#include <iostream>

#include "shortcutwidget.h"
#include "mainwindow.h"

#include "shortcutconfig.h"

#include "appearanceconfig.h"
#include "exceptionsconfig.h"


#include "historyconfig.h"
#include "notificationsconfig.h"
#include "proxyconfig.h"
#include "translationconfig.h"
#include "pronounceconfig.h"

#include "exceptions.h"
#include "languagesconfig.h"



inline void help();
inline void version();
inline void googleIt();


int main(int argc, char *argv[]){



    QApplication app(argc, argv);


    MainWindow mw;
    mw.show();

    return app.exec();



    QString src_lang , dest_lang, src_text;
        bool auto_detect = false;

        bool show_help = false;


        // Command line arguments handling
        for(int i = 0; i < app.arguments().size(); i++) {
            const QString arg = app.arguments().at(i);
            const int args_size = app.arguments().size();

            if(arg == "-s" || arg == "--source_lang") {
                if(args_size> i + 1)
                    src_lang = app.arguments().at(i + 1);
            } else if(arg == "-d" || arg == "--destination_lang") {
                if(args_size > i + 1)
                    dest_lang = app.arguments().at(i + 1);
            } else if(arg == "-a" || arg == "--auto_detect") {
                    auto_detect = true;
            } else if(arg == "-t" || arg == "--text") {
                if(args_size > i + 1)
                    src_text = app.arguments().at(i + 1);
            } else if(arg == "-h" || arg == "--help") {
               help();
            } else if(arg == "-v" || arg == "--version") {
                 version();
            } else if(arg == "-g" || arg == "--google" || arg == "--cake") {
                googleIt();
            }
        }

        if(app.argc() > 1) {
            Translate t;
            if(src_lang.isEmpty() && !auto_detect || dest_lang.isEmpty() || src_text.isEmpty()) {
                 help();
            } else if(auto_detect) {
                const QStringList keys/* = LanguagesFactory::shortList()*/;
                src_lang  = keys.at(t.getLanguageIndex(src_text));
                qDebug()  << t.translate(src_lang, dest_lang, src_text);
                exit(0);
            } else {
                qDebug() << t.translate(src_lang, dest_lang, src_text);
                exit(0);
            }
            return 0;
        }

    return app.exec();
}

inline void help() {
    static  QString help;
    help.append("Usage:\n");
    help.append("Common options\n");
    help.append("-h --help\t\tfor this help\n");
    help.append("-v --version\t\tfor show version\n");
    help.append("-s -- source_lang\t\tsource language\n");
    help.append("-d --destination_lang\t\tfor destination language\n");
    help.append("-a --auto_detect\t\tfor source language auto detection\n");
    help.append("-t --text\t\t for source text\n\n");
    help.append("Visit http://" + Platform::getApplicationDomain() + " for more information.\n");
#ifdef Q_OS_UNIX
    help.append("Note: this version have cake");
#endif
    std::cout << help.toStdString();
    exit(0);
}

inline void version() {
   qDebug() << Platform::getApplicationVersion();
    exit(0);
}

inline void googleIt() {
#ifdef Q_OS_UNIX
    //34 31 33 34 32 34
    const QStringList data =
	    QStringList()
	    << "\33[34mG"<< "\33[31mo"
	    << "\33[33mo"<< "\33[34mg"
	    << "\33[32ml"<< "\33[31me"
	    << "\33[39m"
	    << " The" << " World" << "!"
	    << "     --- The cake"
	    <<" is" << " a" << " lie---     ";

    std::cout << "\n\n\n\n\n\n\n";
    for(int i = 0; i < data.size(); i++) {
	sleep(1);
	std::cerr << data.at(i).toStdString();
    } //sleep(3);
    std::cout << "\n\n\n\n\n\n\n";
#endif
    exit(0);
}

